#include<bits/stdc++.h>
using namespace std;

typedef struct LinkedList
{
	int index;
	LinkedList* next;
}LL;

void InitLL(LL* &x, int n)
{
	x = new LL;
	x->next = NULL;
	LL *r, *s;
	s = x;
	for(int i = 1;i <= n;i++)
	{
		r = new LL;
		r->index = i;
		s->next = r;
		s = r;
	}
	s->next = x->next;
}

void Joseph(LL* x, int n, int m)
{
	int cnt = 0;
	LL *head, *tail;
	head = x;
	tail = x->next;
	while(tail != head)
	{
		if(tail->index == -1)
		{
			tail = tail->next;
			continue;
		}
		if(++cnt == m)
		{
			cnt = 0;
			n--;
			tail->index = -1;
			tail = tail->next;
		}
		else
			tail = tail->next;
		if(n == 1)
			break;
	}
	while(x->next != NULL)
	{
		x = x->next;
		if(x->index != -1)
		{
			cout<<x->index<<endl;
			break;
		}
	}
}

int main()
{
	int n, m;
	LL* L;
	while(cin>>n>>m && n && m)
	{
		InitLL(L, n);
		Joseph(L, n, m);
	}
    return 0;
}

